home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / misc / 40 / zap2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-07-17  |  2.9 KB  |  116 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* zap.c - version 1.0.3 */
  3.  
  4. #include "hack.h"
  5.  
  6. extern struct obj *mkobj_at();
  7. extern struct monst *makemon(), *mkmon_at(), youmonst;
  8. extern char *exclam();
  9.  
  10. extern char *fl[];
  11.  
  12. /* bhit: called when a weapon is thrown (sym = obj->olet) or when an
  13.    IMMEDIATE wand is zapped (sym = 0); the weapon falls down at end of
  14.    range or when a monster is hit; the monster is returned, and bhitpos
  15.    is set to the final position of the weapon thrown; the ray of a wand
  16.    may affect several objects and monsters on its path - for each of
  17.    these an argument function is called. */
  18. /* check !u.uswallow before calling bhit() */
  19.  
  20. struct monst *
  21. bhit(ddx,ddy,range,sym,fhitm,fhito,obj)
  22. register int ddx,ddy,range;        /* direction and range */
  23. char sym;                /* symbol displayed on path */
  24. int (*fhitm)(), (*fhito)();        /* fns called when mon/obj hit */
  25. struct obj *obj;            /* 2nd arg to fhitm/fhito */
  26. {
  27.     register struct monst *mtmp;
  28.     register struct obj *otmp;
  29.     register int typ;
  30.  
  31.     bhitpos.x = u.ux;
  32.     bhitpos.y = u.uy;
  33.  
  34.     if(sym) tmp_at(-1, sym);    /* open call */
  35.     while(range-- > 0) {
  36.         bhitpos.x += ddx;
  37.         bhitpos.y += ddy;
  38.         typ = levl[bhitpos.x][bhitpos.y].typ;
  39.         if(mtmp = m_at(bhitpos.x,bhitpos.y)){
  40.             if(sym) {
  41.                 tmp_at(-1, -1);    /* close call */
  42.                 return(mtmp);
  43.             }
  44.             (*fhitm)(mtmp, obj);
  45.             range -= 3;
  46.         }
  47.         if(fhito && (otmp = o_at(bhitpos.x,bhitpos.y))){
  48.             if((*fhito)(otmp, obj))
  49.                 range--;
  50.         }
  51.         if(!ZAP_POS(typ)) {
  52.             bhitpos.x -= ddx;
  53.             bhitpos.y -= ddy;
  54.             break;
  55.         }
  56.         if(sym) tmp_at(bhitpos.x, bhitpos.y);
  57.     }
  58.  
  59.     /* leave last symbol unless in a pool */
  60.     if(sym)
  61.        tmp_at(-1, (levl[bhitpos.x][bhitpos.y].typ == POOL) ? -1 : 0);
  62.     return(0);
  63. }
  64.  
  65. struct monst *
  66. boomhit(dx,dy) {
  67.     register int i, ct;
  68.     register struct monst *mtmp;
  69.     char sym = ')';
  70.     extern schar xdir[], ydir[];
  71.  
  72.     bhitpos.x = u.ux;
  73.     bhitpos.y = u.uy;
  74.  
  75.     for(i=0; i<8; i++) if(xdir[i] == dx && ydir[i] == dy) break;
  76.     tmp_at(-1, sym);    /* open call */
  77.     for(ct=0; ct<10; ct++) {
  78.         if(i == 8) i = 0;
  79.         sym = ')' + '(' - sym;
  80.         tmp_at(-2, sym);    /* change let call */
  81.         dx = xdir[i];
  82.         dy = ydir[i];
  83.         bhitpos.x += dx;
  84.         bhitpos.y += dy;
  85.         if(mtmp = m_at(bhitpos.x, bhitpos.y)){
  86.             tmp_at(-1,-1);
  87.             return(mtmp);
  88.         }
  89.         if(!ZAP_POS(levl[bhitpos.x][bhitpos.y].typ)) {
  90.             bhitpos.x -= dx;
  91.             bhitpos.y -= dy;
  92.             break;
  93.         }
  94.         if(bhitpos.x == u.ux && bhitpos.y == u.uy) { /* ct == 9 */
  95.             if(rn2(20) >= 10+u.ulevel){    /* we hit ourselves */
  96.                 (void) thitu(10, rnd(10), "boomerang");
  97.                 break;
  98.             } else {    /* we catch it */
  99.                 tmp_at(-1,-1);
  100.                 pline("Skillfully, you catch the boomerang.");
  101.                 return(&youmonst);
  102.             }
  103.         }
  104.         tmp_at(bhitpos.x, bhitpos.y);
  105.         if(ct % 5 != 0) i++;
  106.     }
  107.     tmp_at(-1, -1);    /* do not leave last symbol */
  108.     return(0);
  109. }
  110.  
  111. char
  112. dirlet(dx,dy) register dx,dy; {
  113.     return
  114.         (dx == dy) ? '\\' : (dx && dy) ? '/' : dx ? '-' : '|';
  115. }
  116.